package com.njtoyo.taxi.admin.rest.controller.business;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njtoyo.netrides.entity.CompanyBank;
import com.njtoyo.taxi.admin.rest.presenter.business.driver_withdraw.DriverWithdrawListPresenter;
import com.njtoyo.taxi.admin.rest.wrapper.business.company.AddCompanyWithdrawWrapper;
import com.njtoyo.taxi.admin.rest.wrapper.business.company.CompanyWithdrawWrapper;
import com.njtoyo.taxi.admin.rest.wrapper.business.driver_withdraw.IndexWrapper;
import com.njtoyo.taxi.admin.service.business.CompanyBankService;
import com.njtoyo.taxi.admin.service.business.CompanyWithdrawService;
import com.njtoyo.taxi.entity.backend.AdminUser;
import com.taxi.entity.common.RestResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

@RestController
@RequestMapping("business/company-withdraw")
public class CompanyWithdrawController {

    @Autowired
    private CompanyBankService companyBankService;
    @Autowired
    private CompanyWithdrawService companyWithdrawService;

    @GetMapping("/list")
    public RestResult index(@ApiIgnore @ModelAttribute("admin") AdminUser adminUser, CompanyWithdrawWrapper wrapper) {
        return companyBankService.getPage(adminUser, wrapper);
    }


    @GetMapping("/{companyId}/getByCompanyId")
    RestResult getByCompanyId(@PathVariable("companyId") Long companyId) {
        return companyBankService.getByCompanyId(companyId);
    }

    @GetMapping("/getCompanyBalance")
    RestResult getCompanyBalance() {
        return companyBankService.getCompanyBalance();
    }

    @PostMapping("/addWithdraw")
    RestResult saveOrUpdate(@ApiIgnore @ModelAttribute("admin") AdminUser adminUser,@RequestBody AddCompanyWithdrawWrapper add) {
        if (StrUtil.isBlank(add.getBankName())) {
            return RestResult.failed("请输入银行名称");
        }
        if (StrUtil.isBlank(add.getNameOnCard())) {
            return RestResult.failed("请输入收款人姓名");
        }
//        if (StrUtil.isBlank(add.getCardNumber())) {
//            return RestResult.failed("请输入卡号");
//        }
        if (StrUtil.isBlank(add.getBankCity())) {
            return RestResult.failed("请输入开户城市");
        }
        if (ObjectUtil.isNull(add.getAmount())) {
            return RestResult.failed("请输入提现金额");
        }
        return companyWithdrawService.addWithdraw(adminUser,add);
    }

    // 通过审核
    @PostMapping("/pass")
    RestResult pass(@ApiIgnore @ModelAttribute("admin") AdminUser adminUser,@RequestBody AddCompanyWithdrawWrapper add) {
        return companyWithdrawService.pass(adminUser,add);
    }

    // 未通过审核
    @PostMapping("/reject")
    RestResult reject(@ApiIgnore @ModelAttribute("admin") AdminUser adminUser,@RequestBody AddCompanyWithdrawWrapper add) {
        return companyWithdrawService.reject(adminUser,add);
    }
}
